package com.think.teaching.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.think.common.utils.Common;
import com.think.teaching.model.VrLessonDocument;
import com.think.teaching.mapper.VrLessonDocumentMapper;

@Service
public class VrLessonDocumentServiceImpl extends BaseServiceImpl<VrLessonDocumentMapper, VrLessonDocument> {
	
	public VrLessonDocument GetVrLessonDocumentById(Integer id) {
		return this.getById(id);
	}
	
	public VrLessonDocument AddVrLessonDocument(VrLessonDocument data) {
		data.setCreatedBy(Common.GetCurrentAuthor().getUserId());
		return this.save(data)?data:null;
	}
	
	public IPage<VrLessonDocument> ListVrLessonDocument(Integer page,Integer count,Integer lessonId,Boolean withoutBan){
		IPage<VrLessonDocument> iPage = new Page<VrLessonDocument>(page,count);
		QueryWrapper<VrLessonDocument> queryWrapper = new QueryWrapper<VrLessonDocument>();
		queryWrapper.ne("delflag", 1).eq("vr_lesson_id", lessonId);
		if (withoutBan) {
			queryWrapper.eq("state", 1);
		}
		queryWrapper.orderByDesc("`created_time`");
		return this.page(iPage,queryWrapper);
	}
	
	public List<VrLessonDocument> GetAllVrLessonDocumentByLessonId(Integer lessonId){
		QueryWrapper<VrLessonDocument> queryWrapper = new QueryWrapper<VrLessonDocument>();
		queryWrapper.ne("delflag", 1).eq("vr_lesson_id", lessonId).eq("state", 1).orderByDesc("created_time");
		return this.list(queryWrapper);
	}
	
	public Boolean DeleteVrLessonDocument(Integer id) {
		UpdateWrapper<VrLessonDocument> updateWrapper = new UpdateWrapper<VrLessonDocument>();
		updateWrapper.eq("id", id).set("delflag", 1);
		return this.update(updateWrapper);
	}
	
	public Boolean UpdateVrLessonDocument(VrLessonDocument data) {
		data.setUpdatedBy(Common.GetCurrentAuthor().getUserId());
		return this.updateById(data);
	}
}
